package work.fram;


import java.util.HashMap;
import java.util.Map;

//映射辅助器
public class MappingHelper {

    private Map<String, String> mapper = new HashMap<>();

    public void putKey(String old, String now) {
        mapper.put(old, now);
    }

    public <t> Map<String, t> map(Map<String, t> o, boolean ignoreNull) {
        Map<String, t> tMap = new HashMap<>();
        if (ignoreNull) {
            o.forEach((k, v) -> {
                String s = mapper.get(k);
                if (s != null) {
                    tMap.put(s, v);
                }
            });
        } else {
            o.forEach((k, v) -> {
                String s = mapper.get(k);
                if (s == null) {
                    tMap.put(k, v);
                } else {
                    tMap.put(s, v);
                }
            });
        }
        return tMap;
    }
}
